﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CSP.Model.CSPEnum;
using CSP.Bll;
using CSP.Bll.IObjectBlls;
using CSP.Common.Web;

namespace CSP.Web.MyHome.Activity.CollectBusinessInfo
{
    public partial class Add : CSPMyHome
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }



        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            if(String.IsNullOrWhiteSpace(TxtName.Value))
            {
                Alert("请填写机构/个人名称");
            }
            AddCollectBusinessInfo();
        }

        /// <summary>
        /// 添加商家信息
        /// </summary>
        private void AddCollectBusinessInfo()
        {
            CSPBllFactory bllFactory = CSPBllFactory.GetInstance();
            CSP.Model.CSP.CollectBusinessInfo collectBusinessInfo = GetCollectBusinessInfo();

            using (ICollectBusinessInfoBll collectBusinessBll = bllFactory.GetCollectBusinessInfoBll())
            {
                try
                {
                    collectBusinessBll.Add(collectBusinessInfo);
                }
                catch (Exception ex)
                {
                    LoggerProvider.Error(ex);
                    this.FailRedirect("提交未失败", "/MyHome/Activity/CollectBusinessInfo/List.aspx");
                }
                this.SuccessfullRedirect("提交成功", "/MyHome/Activity/CollectBusinessInfo/List.aspx");
            }

        }

        /// <summary>
        /// 获取商家搜集信息
        /// </summary>
        /// <returns></returns>
        private CSP.Model.CSP.CollectBusinessInfo GetCollectBusinessInfo()
        {
            CSP.Model.CSP.CollectBusinessInfo info = new Model.CSP.CollectBusinessInfo();
            info.Name = this.TxtName.Value;
            info.Phone = this.TxtPhone.Value;
            info.Mobile = this.TxtMobile.Value;
            info.Remark = this.TxtRemark.Value;
            info.UserName = this.UserProvider.UserName;
            info.Status = (int)CollectBusinessInfoStatus.Processing;
            return info;
        }
    }
}